<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<head>
<meta http-equiv="Content-Type" content="text/html; charset="utf-8" />
<title>无标题文档</title>
<link rel="stylesheet" type="text/css" href="../css/easyui.css">
<link rel="stylesheet" type="text/css" href="../css/icon.css">
<link rel="stylesheet" type="text/css" href="../css/demo.css">

<!-- <script src="../js/jquery-1.8.3.js" type="text/javascript"></script> -->
<script src="../js/jquery.min.js"></script> 
<script src="../js/jquery.easyui.min.js"></script>

<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
.STYLE1 {font-size: 12px}
.STYLE3 {font-size: 12px; font-weight: bold; }
.STYLE4 {
	color: #03515d;
	font-size: 12px;
}
-->
</style>

<script>
var  highlightcolor='#c1ebff';
//此处clickcolor只能用win系统颜色代码才能成功,如果用#xxxxxx的代码就不行,还没搞清楚为什么:(
var  clickcolor='#51b2f6';
function  changeto(){
source=event.srcElement;
if  (source.tagName=="TR"||source.tagName=="TABLE")
return;
while(source.tagName!="TD")
source=source.parentElement;
source=source.parentElement;
cs  =  source.children;
//alert(cs.length);
if  (cs[1].style.backgroundColor!=highlightcolor&&source.id!="nc"&&cs[1].style.backgroundColor!=clickcolor)
for(i=0;i<cs.length;i++){
	cs[i].style.backgroundColor=highlightcolor;
}
}

function  changeback(){
if  (event.fromElement.contains(event.toElement)||source.contains(event.toElement)||source.id=="nc")
return
if  (event.toElement!=source&&cs[1].style.backgroundColor!=clickcolor)
//source.style.backgroundColor=originalcolor
for(i=0;i<cs.length;i++){
	cs[i].style.backgroundColor="";
}
}

function  clickto(){
source=event.srcElement;
if  (source.tagName=="TR"||source.tagName=="TABLE")
return;
while(source.tagName!="TD")
source=source.parentElement;
source=source.parentElement;
var cs  =  source.children;
//alert(cs.length);
if  (cs[1].style.backgroundColor!=clickcolor&&source.id!="nc")
for(i=0;i<cs.length;i++){
	cs[i].style.backgroundColor=clickcolor;
}
else
for(i=0;i<cs.length;i++){
	cs[i].style.backgroundColor="";
}
}
	$(function(){
		var ctx = "${ctx}";
		
		var userIds = new Array();
		
		
		$('#addUserdlg').dialog({ 
			collapsible: true, 
			minimizable: true, 
			maximizable: true,  
			buttons: [{ 
				text: '提交', 
				iconCls: 'icon-ok', 
				handler: function() { 
					var userName=$("#name").val();
					var pwd=$("#pwd").val();
					var nextPwd = $("#twoPwd").val();
					if(checkInputValidate(userName,pwd,nextPwd)){
						$("#addUserForm").submit();
					}else{
						return;
					}
				}},
				{ 
				text: '取消', 
				handler: function() { 
					$('#addUserdlg').dialog('close'); 
					} 
				}] 
			}); 
		$('#editUserdlg').dialog({ 
			collapsible: true, 
			minimizable: true, 
			maximizable: true,  
			buttons: [{ 
				text: '提交', 
				iconCls: 'icon-ok', 
				handler: function() {
					$("#editUserForm").submit();
				}},
				{ 
				text: '取消', 
				handler: function() { 
					$('#editUserdlg').dialog('close'); 
					} 
				}] 
			});
		
		
		$("#editUserdlg").dialog('close');
		$("#addUserdlg").dialog('close');			//默认关闭状态
		//验证输入
		function checkInputValidate(userName,pwd,twoPwd){
			if(name.lengt<0||name==null){
				alert("用户名不能为空，请输入用户名");
				return false;
			}else if(pwd.length<6||twoPwd.length<6){
				alert("密码长度不能少于6位数");
				return false;
			}else if(pwd!=twoPwd){
				alert("两次输入的密码不相符！请重新输入");
				return false;
			}else{
				return true;
			}
		}
		
		$("#allCkBox").click(function(){
			//全选
			 if(this.checked){
				 $("input[name='userCK']:checkbox").each(function () {
	                    $(this).prop("checked", true);
	                    userIds[i]=$(this).val();
	                    //alert(userIds[i]);
	                    //this.checked==this.checked;
	                });
				// alert("全选");
			}else{
				$("input[name='userCK']:checkbox").each(function () {
	                  $(this).prop("checked", false);
	                  //this.checked!=this.checked; 
	              });
				// alert("全否");
			}
		});
		
		//删除
		$("#del").click(function(){
			if(userIds=="undefined"||userIds.length==0){
				alert("请选择要删除的选项在进行相关操作!");
			}else{
				alert(userIds);
			}
		});
	
		
		$("#add").click(function(){
			$('.g-zhegai').show();
			$("#addUserdlg").dialog('open');
		});
	});
	
	function edit(userId,userName,disabled){
		$("#userId").val(userId);
		$("#editName").val(userName);
		if(disabled===1){
			$("#disabled").prop("checked","checked");
		}else{
			$("#able").prop("checked","checked");
		}
		$("#editUserdlg").dialog('open');
	};
	
	
	function del(userId){
		$.post(
			ctx+"/user/delUser.go",
			{userId:userId},
			function(data){
				if(data=="success"){
					window.href.reload();
				}else{
					alert("删除失败");
				}
			}
		);
	};
	
	
	
	
</script>

</head>

<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="30" background="../images/tab_05.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="12" height="30"><img src="../images/tab_03.gif" width="12" height="30" /></td>
        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="46%" valign="middle"><table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="5%"><div align="center"><img src="../images/tb.gif" width="16" height="16" /></div></td>
                <td width="95%" class="STYLE1"><span class="STYLE3">你当前的位置</span>：[用户管理]-[用户列表]</td>
              </tr>
            </table></td>
            <td width="54%"><table border="0" align="right" cellpadding="0" cellspacing="0">
              <tr>
                <td width="60"><table width="87%" border="0" cellpadding="0" cellspacing="0">
                  <tr>
                    <td class="STYLE1"><div align="center">
                      <input id="allCkBox" type="checkbox" name="checkbox62" value="checkbox" />
                    </div></td>
                    <td class="STYLE1"><div align="center">全选</div></td>
                  </tr>
                </table></td>
                <td width="60"><table width="90%" border="0" cellpadding="0" cellspacing="0">
                  <tr>
                    <td class="STYLE1"><div align="center"><img src="../images/22.gif" width="14" height="14" /></div></td>
                    <td class="STYLE1"><a href="#" id="add"><div align="center">新增</div></a></td>
                  </tr>
                </table></td>
                <!-- <td width="60"><table width="90%" border="0" cellpadding="0" cellspacing="0">
                  <tr>
                    <td class="STYLE1"><div align="center"><img src="../images/33.gif" width="14" height="14" /></div></td>
                    <td class="STYLE1"><a id="edit"><div align="center">修改</div></a></td>
                  </tr>
                </table></td> -->
                <td width="52"><table width="88%" border="0" cellpadding="0" cellspacing="0">
                  <tr>
                    <td class="STYLE1"><div align="center"><img src="../images/11.gif" width="14" height="14" /></div></td>
                    <td class="STYLE1"><a href="javascript:void(0);" id="del"><div align="center">删除</div></a></td>
                  </tr>
                </table></td>
              </tr>
            </table></td>
          </tr>
        </table></td>
        <td width="16"><img src="../images/tab_07.gif" width="16" height="30" /></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="8" background="../images/tab_12.gif">&nbsp;</td>
        <td><table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="b5d6e6" onmouseover="changeto()"  onmouseout="changeback()">
          <tr>
            <td width="3%" height="22" background="../images/bg.gif" bgcolor="#FFFFFF"><div align="center">
              <input type="checkbox" name="checkbox" value="checkbox" />
            </div></td>
            <td width="3%" height="22" background="../images/bg.gif" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">序号</span></div></td>
            <td width="12%" height="22" background="../images/bg.gif" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">用户名</span></div></td>
            <td width="12%" height="22" background="../images/bg.gif" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">是否禁用</span></div></td>
            <td width="14%" height="22" background="../images/bg.gif" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">上次登录时间</span></div></td>
            <td width="15%" height="22" background="../images/bg.gif" bgcolor="#FFFFFF" class="STYLE1"><div align="center">基本操作</div></td>
          </tr>
          <c:forEach var="user" items="${users }" >
          	 <tr>
           		 <td height="20" bgcolor="#FFFFFF"><div align="center">
              		<input class="ckBox" type="checkbox" name="userCK" value="${user.userId }" />
            		</div></td>
            	<td height="20" bgcolor="#FFFFFF"><div align="center" class="STYLE1">
              	<div align="center">${user.userId }</div>
           		</div>
           	</td>
            <td height="20" bgcolor="#FFFFFF"><div  align="center"><span class="STYLE1">${user.userName }</span></div></td>
            <td height="20" bgcolor="#FFFFFF"><div  align="center"><span class="STYLE1">${user.disabled == 0?"否":"是" } </span></div></td>
             <td height="20" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">${user.lastLoginTime } </span></div></td>
<!--             <td bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">tiezhu0902@163.com</span></div></td>
            <td height="20" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">南京科技股份有限公司…</span></div></td> -->
            <td height="20" bgcolor="#FFFFFF"><div align="center"><span class="STYLE4"><a href="javascript:void(0);" onclick="edit('${user.userId}','${user.userName }','${user.disabled }')"><img src="../images/edt.gif" width="16" height="16" />编辑</a>&nbsp; &nbsp;<a href="javascript:void(0); onclick=del(${user.userId})"><img src="../images/del.gif" width="16" height="16" />删除</a></span></div></td>
         	 </tr>
          </c:forEach>
         
        </table></td>
        <td width="8" background="../images/tab_15.gif">&nbsp;</td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td height="35" background="../images/tab_19.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="12" height="35"><img src="../images/tab_18.gif" width="12" height="35" /></td>
        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td class="STYLE4">&nbsp;&nbsp;共有 ${count } 条记录，当前第${pageNum+1 } 页</td>
            <td><table border="0" align="right" cellpadding="0" cellspacing="0">
                <tr>
                  <td width="40"><a href="${ctx}/user/userManager.go?pageNum=0"><img src="../images/first.gif" width="37" height="15" /></a></td>
                  <td width="45"><a href="${ctx}/user/userManager.go?pageNum=${pageNum-1}"><img src="../images/back.gif" width="43" height="15" /></a></td>
                  <td width="45"><a href="${ctx}/user/userManager.go?pageNum=${pageNum+1}"><img src="../images/next.gif" width="43" height="15" /></a></td>
                  <td width="40"><a href="${ctx}/user/userManager.go?pageNum=${pageSum}"><img src="../images/last.gif" width="37" height="15" /></a></td>
                  <td width="100"><div align="center"><span class="STYLE1">转到第
                    <input name="textfield" type="text" size="4" style="height:12px; width:20px; border:1px solid #999999;" /> 
                    页 </span></div></td>
                  <td width="40"><img src="../images/go.gif" width="37" height="15" /></td>
                </tr>
            </table></td>
          </tr>
        </table></td>
        <td width="16"><img src="../images/tab_20.gif" width="16" height="35" /></td>
      </tr>
    </table></td>
  </tr>
</table>

<!-- 添加用户 -->
<div id="addUserdlg" class="easyui-dialog" title="添加用户" data-options="iconCls:'icon-save'" style="width:400px;height:200px;padding:10px">
		<form id="addUserForm" action="addUser.go" method="post">
			<table>
				<tr>
					<td>用户名:</td>
					<td><input type="text" name="name" id="name" class="name"/></td>
				</tr>
				<tr>
					<td>密码:</td>
					<td><input type="password" name="password" id="pwd" class="pwd"/></td>
				</tr>
				<tr>
					<td>请再次输入密码:</td>
					<td><input type="password" name="morePassword" id="twoPwd" class="pwd"/></td>
				</tr>
			</table>
		</form>
</div>
<!-- <div style="width:100%;height:100%;position:fixed;left:0;top:0;background:#ccc;display:none;" class="g-zhegai"></div> -->

<!-- 编辑用户 -->
<div id="editUserdlg" class="easyui-dialog" title="编辑用户" data-options="iconCls:'icon-save'" style="width:400px;height:200px;padding:10px">
		<form id="editUserForm" action="editUser.go" method="post">
			<div id="editUserDV" style="margin:0,auto">
			<table>
					<input type="text" id="userId" name="userId" class="userId" hidden="display"/>
				<tr>
					<td>用户名:</td>
					<td><input type="text" name="userName" id="editName" class="name"/></td>
				</tr>
				<tr>
					<td>是否禁用:</td>
					<td><input type="radio" id="disable" name="disabled" value="0"/>是
						<input type="radio" id="able" name="disabled" value="1"/> 否
					</td>
				</tr>
			</table>
			</div>
		</form>
</div>


</body>
</html>
